package com.hyl.gulimall.order.controller;

import com.hyl.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMq")
    public String sendMq(){
        //1.发送消息、如果发送的消息是个对象，我们会使用序列化机制，将对象写出去，对象必须实现Serializoble

        OrderEntity orderEntity=new OrderEntity();
        orderEntity.setBillHeader("哈哈哈哈");

        //2.发送的对象类型的消息，可以是一个json
        rabbitTemplate.convertAndSend("hello-java-exchange","hello.java",orderEntity);
     return "ok";
    }

}
